// pages/newMessageRequire/BuyMessage/BuyMessage.js
var util = require('../../../utils/util')
Page({

    /**
     * 页面的初始数据
     */
    data: {
        imageList:[],
        isjointsec:["整租","合租"],
        indexE:0,
        indexP:0,
        indexR:0,
        indexIsjoint:0,
        elevatorsec:["有电梯","无电梯"],
        orentationsec:["正南","正北","正东","正西","南北","东西","东南","西南","东北","西北"],
        datas:{ 
          isjoint:"整租",
          kind:"出租",
          username:"",
          title:"",
          phone:"",
          lease:"",
          type:"",
          funiture:"",
          requirement:"",
          orentation:"正南",
          floor:"",
          decoration:"",
          elevator:"有电梯",
          area:0,
          price:0,
          location:"",
          date:"",
          picture:"",
          other:""
         }
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    },
    getImage:function(){
        var that= this
        wx.chooseImage({
          count: 9,
          sizeType:["original","compressed"],
          sourceType:["album","camera"],
          success(res){
            that.setData({
                imageList:that.data.imageList.concat(res.tempFilePaths)
            })
          }
        })
    },
    setHouseTitle:function(e){
        this.setData({
          datas:{
            title:e.detail.value
          }
        })
        console.log(this.data.datas.title)
    },
    HouseArea:function(e){
      this.setData({
        datas:{
          area:e.detail.value
        }
      })
      console.log(this.data.datas.area)

  },
  HouseType:function(e){
    this.setData({
      datas:{
        type:e.detail.value
      }
    })
    console.log(this.data.datas.type)
    
  },
  HouseFloor:function(e){
    this.setData({
      datas:{
        floor:e.detail.value
      }
    })
    console.log(this.data.datas.floor)
    
  },
  HouseDecoration:function(e){
    this.setData({
      datas:{
        decoration:e.detail.value
      }
    })
    console.log(this.data.datas.decoration)
    
  },
  HouseLoc:function(e){
    this.setData({
      datas:{
        location:e.detail.value
      }
    })
    console.log(this.data.datas.location)
    
  },
  HousePrice:function(e){
    this.setData({
      datas:{
        price:e.detail.value
      }
    })
    console.log(this.data.datas.price)
    
  },
  HouseRequirement:function(e){
    this.setData({
      datas:{
        requirement:e.detail.value
      }
    })
    console.log(this.data.datas.requirement)
    
  },
  HouseFuniture:function(e){
    this.setData({
      datas:{
        funiture:e.detail.value
      }
    })
    console.log(this.data.datas.funiture)
    
  },
  HouseOther:function(e){
    this.setData({
      datas:{
        other:e.detail.value
      }
    })
    console.log(this.data.datas.other)
    
    
  },
  HouseLease:function(e){
    this.setData({
      datas:{
        lease:e.detail.value
      }
    })
    console.log(this.data.datas.lease)
    
    
  },
  bindPickerChangeE:function(e)
  {
    this.setData({
      datas:{elevator:this.data.elevatorsec[e.detail.value]},
      indexE:e.detail.value
    })
    console.log(this.data.datas.elevator)
  },
  bindPickerChangeIsjoint:function(e)
  {
    this.setData({
      datas:{isjoint:this.data.isjointsec[e.detail.value]},
      indexIsjoint:e.detail.value
    })
    console.log(this.data.datas.isjoint)
  },
  bindPickerChangeR:function(e)
  {
    this.setData({
      datas:{lease:e.detail.value}
    })
    console.log(this.data.datas.lease)
  },
  bindPickerChangeO:function(e)
  {
    this.setData({
      datas:{orentation:this.data.orentationsec[e.detail.value]},
      indexP:e.detail.value
    })
    console.log(this.data.datas.orentation)
  },
  HouseTel:function(e){
    this.setData({
      datas:{
        phone:e.detail.value
      }
    })
    console.log(this.data.datas.phone)
  },
  submitbut:function()
  {
    var token=wx.getStorageSync('token')
    var username=wx.getStorageSync('username')
    var that=this
    wx.showToast({
      title: '加载中',
      duration: 4000,
      icon: "loading",

    })
    wx.request({
      url: 'http://192.168.1.100/house/v1/myinfo/'+username+'/'+token,
      method:'POST',
      data:{
          kind:that.data.datas.kind,
          username:that.data.datas.username,
          title:that.data.datas.title,
          phone:that.data.datas.phone ,
          isjoint:that.data.datas.isjoint,
          funiture:that.data.datas.funiture,
          requirement:that.data.datas.requirement,
          type:that.data.datas.type,
          lease:that.data.datas.lease,
          orentation:that.data.datas.orentation,
          floor:that.data.datas.floor,
          decoration:that.data.datas.decoration,
          elevator:that.data.datas.elevator,
          area:that.data.datas.area,
          price:that.data.datas.price,
          location:that.data.datas.location,
          other:that.data.datas.other,
          picture:that.data.datas.imageList,
     
          date: util.formatDate(new Date())
 
      },
      success:function(res)
      {
        if(res.data.code==200)
        {
          wx.showToast({
            title: '发布成功',
            duration: 2000,
            icon: "success",

          })
          wx.switchTab({
            url: '/pages/new/new',
          })
        }
        else{
          wx.showToast({
            title: res.data.message,
            duration: 2000,
            icon: "error",

          })
        }
      },
      fail:function(res)
      {
        wx.showToast({
          title: "连接超时",
          duration: 2000,
          icon: "error",

        })
      }
    })
  }
})